Static and Dynamic Behavior לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון
|
|
- Lynette Gallagher
- 6 years ago
- Views:
Transcription
1 Static and Dynamic Behavior לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון
2 22 Roadmap In this chapter we will examine how differences in static and dynamic features effect object-oriented programming languages: Static versus Dynamic Typing Static and Dynamic Classes in Statically Typed Languages Static and Dynamic Method Binding in Statically Typed Languages
3 33 What do the terms Static and Dynamic Mean? In programming languages: Static almost always means fixed or bound at compile time, and cannot thereafter be changed Dynamic almost always means not fixed or bound until run time, and therefore can change during the course of execution
4 44 Static and Dynamic Typing In a statically typed programming language (e.g., Java or Pascal), for example, variables have declared typed -- fixed at compile time In a dynamically typed programming language (e.g., Smalltalk or LISP), a variable is just a name. Types are associated with values, not variables. A variable can hold different types during the course of execution
5 55 Arguments for and Against Static typing allows better error detection, more work at compile time and hence faster execution time Dynamic typing allows greater flexibility, easier to write (for example, no declaration statements)
6 66 Both arguments have some validity, and hence both types of languages will continue to exist in the future
7 77 The Polymorphic Variable The addition of object-oriented ideas in a statically typed languages adds a new twist Recall the argument for substitution: an instance of a child class should be allowed to be assigned to a variable of the parent class: var pet : Mammal; fido : Dog; felice: Cat; begin pet := fido; // legal pet := felice; // legal fido := pet; // not legal
8 88 Static Class and Dynamic Class In a statically typed OO language we say the class of the declaration is the static class for the variable While the class of the value it currently holds is the dynamic class Most statically typed OO languages constrain the dynamic class to be a child class of the static class var pet : Mammal; fido : Dog begin pet := fido; // static class is Mammal, dynamic class is Dog end;
9 99 Importance of Static Class In a statically typed object-oriented language, the legality of a message is determined at compile time, based on the static class A message can produce a compile error, even if no run-time error could possibly arise: class Mammal { } class Dog extends Mammal { void speak() { System.out.println("woof"); } } Mammal pet = new Dog; pet.speak(); // will generate error, Mammals don't speak
10 10 Run Time Determination The principle of substitution can be viewed as moving a value up the inheritance hierarchy Occasionally it is necessary to do the reverse: To determine if a value currently being held by a variable declared with one class type is, in fact, derived from a class that is lower in that class hierarchy For example: To determine if a variable of type Animal is, in fact, a Dog Animal Animal apet = fido Cat Dog fido
11 11 Reverse Polymorphism / Down Casting Polymorphism says we can assign a value from a child class to an instance of the parent class, but can this assignment then be reversed? Under what conditions? var pet : Mammal; fido : Dog; felice : Cat; begin pet := fido; // legal fido := pet; // is this legal? end; This is known as the problem of reverse polymorphism
12 12 Two aspects of reverse polymorphism There are two specific problems associated with the question of reverse polymorphism. The problem of identity - can I tell if a value declared as an instance of a parent class actually holds a value from a subclass The task of assignment - can I then assign the value from the parent class to a variable declared as the subclass In some languages mechanisms are provided to address these two problems together, while in other languages they are separated
13 13 Run-time testing without language support class Animal { public: virtual Dog * isdog() {return NULL;} virtual Bird * isbird () {return NULL;} }; class Dog : public Animal { virtual Dog * isdog() {return this; } };
14 14 Testing Message Understanding In dynamically typed OO languages it is generally true that the legality of a message passing expression cannot be known until run-time If the receiver does not know how to respond to a message, a run-time exception is thrown Occasionally, it is useful for the programmer to be able to test whether a receiver will understand a particular message before actually attempting to pass the message to the receiver Languages provide different mechanisms to do this: Smalltalk: (apet respondsto: #bark) iftrue: [ ] Ruby: if apet.respond_to?( bark ) Objective-C: if ( [apet ] ) { }
15 15 The Container Problem The task of reverse polymorphism is often encountered in connection with a collection of values: We have a list of items from the parent class (say a list of Mammals), and when we extract a value we need to know if it is a more specific type Generally occurs in languages with a single inheritance tree, where the only type we may have associated with a value is the class Object Solving this problem generally requires values to have self knowledge of their own type In some languages they do, in some languages values do not
16 16 Static and Dynamic Method Binding Should the binding for information be associated with the static class of a variable or the dynamic class? Alice holds a small Mammal - asks Bill does this animal give birth to live young : Static answer: All mammals give birth to live young - therefore yes What if the Mammal is a platypus? Dynamic answer: Platypus lay eggs, therefore no Even statically typed OOP languages can use dynamic binding. But may use static type to determine legality of operation.
17 17 Documenting Method Binding In many languages dynamic binding is the default. If a child class overrides a method in the parent, using the same type signature, then the selected method will be determined by the dynamic type In other languages (C++, Delphi, C#) the programmer must indicate which methods are dynamically bound and which are statically type. In C#, for example, this is done using the virtual and override keywords class Animal { public: virtual void speak () { cout << "Animal Speak!\n"; } void reply () { cout << "Animal Reply!\n"; } }; class Dog : Animal { public: override void speak () { cout << "woof!\n"; } void reply () { cout << "woof again!\n"; } }; class Bird : Animal { public: override void speak () { cout << "tweet!\n"; } }; Animal a; Dog b; b.speak(); woof! a = b; a.speak(); woof! Bird c; c.speak(); tweet! a = c; a.speak(); tweet!
18 18 Method Binding in C++ C++ is the most complex language. Not only must the programmer use the virtual keyword, but true polymorphism only occurs with pointer or reference variables. class Animal { public: virtual void speak () { cout << "Animal Speak!\n"; } void reply () { cout << "Animal Reply!\n"; } }; class Dog : public Animal { public: virtual void speak () { cout << "woof!\n"; } void reply () { cout << "woof again!\n"; } }; class Bird : public Animal { public: virtual void speak () { cout << "tweet!\n"; } }; Animal * a; Dog * b = new Dog(); b->speak(); woof! a = b; a->speak(); woof! Bird c = new Bird(); c->speak(); tweet! a = c; a->speak(); tweet! We will see an explanation for the curious C++ semantics when we discuss memory management in the next chapter.
19 19 Merits of Static versus Dynamic Method Binding Arguments concerning static versus dynamic binding mirror those concerning static versus dynamic typing: Efficiency - static binding uses least CPU cycles, dynamic binding requires more time Error detection - static binding permits errors to be caught at compile time rather than run-time Flexibility - dynamic binding permits greater flexibility, static binding creates rigidity and inhibits reuse
20 20 Chapter Summary A statically typed language associated types with variables, a dynamically typed language associates types with values Static typing gives better error detection, better run-time efficiency, less flexibility In a statically typed OO language, an object variable can still hold values from a child class The static class is the class of the declaration, the dynamic class is the class of the value currently held The legality of a message is checked using the static class A message can be bound to a method using either the static or dynamic class. Most languages use the dynamic class. Some languages allow the programmer to choose which method is used
Static and Dynamic Behavior עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מובסס על הרצאות של אותו קורס שניתן בשנים הקודמות ע "י ד"ר גרא וייס
Static and Dynamic Behavior עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מובסס על הרצאות של אותו קורס שניתן בשנים הקודמות ע "י ד"ר גרא וייס 2 Roadmap In this chapter we will examine how differences
More informationOverriding המחלקה למדעי המחשב עזאם מרעי אוניברסיטת בן-גוריון
Overriding עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap A method in a child class overrides a method in the parent class if it has the same name and type signature: Parent void method(int,float)
More informationInheritance and Substitution גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון
Inheritance and Substitution גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap In this chapter we will start to investigate the concepts of inheritance and substitution: The intuitive and practical
More informationIntroduction to Object-Oriented Programming
Introduction to Object-Oriented Programming Review 2: Object-Oriented Programming Christopher Simpkins chris.simpkins@gatech.edu CS 1331 (Georgia Tech) Review 2: Object-Oriented Programming 1 / 14 Topics
More informationClasses and Methods לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון
Classes and Methods לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון 22 Roadmap Lectures 4 and 5 present two sides of OOP: Lecture 4 discusses the static, compile time representation of object-oriented
More informationMultiple Inheritance לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון
Multiple Inheritance לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון 22 Roadmap In this chapter we will investigate some of the logical problems that can arise when a language allows a child class
More informationOverloading המחלקה למדעי המחשב עזאם מרעי אוניברסיטת בן-גוריון
Overloading עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap In this chapter we will investigate the idea of overloading: Overloading based on scopes Overloading based on type signatures Coercion,
More informationInheritance and Substitution עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מובסס על הרצאות של אותו קורס שניתן בשנים הקודמות ע"י ד"ר גרא וייס
Inheritance and Substitution עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מובסס על הרצאות של אותו קורס שניתן בשנים הקודמות ע"י ד"ר גרא וייס 2 Roadmap In this chapter we will start to investigate the
More informationClasses and Methods גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון
Classes and Methods גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap Lectures 4 and 5 present two sides of OOP: Lecture 4 discusses the static, compile time representation of object-oriented
More informationPolymorphism. Arizona State University 1
Polymorphism CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 15 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University
More informationImplications of Substitution עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון
Implications of Substitution עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap In this chapter we will investigate some of the implications of the principle of substitution in statically typed
More informationInheritance and Substitution (Budd chapter 8, 10)
Inheritance and Substitution (Budd chapter 8, 10) 1 2 Plan The meaning of inheritance The syntax used to describe inheritance and overriding The idea of substitution of a child class for a parent The various
More informationObject interconnections גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון
Object interconnections גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap In this chapter we move up a level of abstraction, and consider collections of objects working together Our focus will
More informationClasses and Methods עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מבוסס על השקפים של אותו קורס שניתן בשנים הקודמות
Classes and Methods עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מבוסס על השקפים של אותו קורס שניתן בשנים הקודמות 2 Roadmap Lectures 4 and 5 present two sides of OOP: Lecture 4 discusses the static,
More informationCS32 - Week 4. Umut Oztok. Jul 15, Umut Oztok CS32 - Week 4
CS32 - Week 4 Umut Oztok Jul 15, 2016 Inheritance Process of deriving a new class using another class as a base. Base/Parent/Super Class Derived/Child/Sub Class Inheritance class Animal{ Animal(); ~Animal();
More informationJava Inheritance. Written by John Bell for CS 342, Spring Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources.
Java Inheritance Written by John Bell for CS 342, Spring 2018 Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources. Review Which of the following is true? A. Java classes may either
More informationWhy use inheritance? The most important slide of the lecture. Programming in C++ Reasons for Inheritance (revision) Inheritance in C++
Session 6 - Inheritance in C++ The most important slide of the lecture Dr Christos Kloukinas City, UoL http://staff.city.ac.uk/c.kloukinas/cpp (slides originally produced by Dr Ross Paterson) Why use inheritance?
More informationMultiple Inheritance עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון
Multiple Inheritance עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap In this chapter we will investigate some of the logical problems that can arise when a language allows a child class to
More informationMore Relationships Between Classes
More Relationships Between Classes Inheritance: passing down states and behaviors from the parents to their children Interfaces: grouping the methods, which belongs to some classes, as an interface to
More informationHAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.
HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all
More informationInheritance and Polymorphism
Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg
More informationTopic 5 Polymorphism. " Inheritance is new code that reuses old code. Polymorphism is old code that reuses new code.
Topic 5 Polymorphism " Inheritance is new code that reuses old code. Polymorphism is old code that reuses new code. 1 Polymorphism Another feature of OOP literally having many forms object variables in
More informationFirst IS-A Relationship: Inheritance
First IS-A Relationship: Inheritance The relationships among Java classes form class hierarchy. We can define new classes by inheriting commonly used states and behaviors from predefined classes. A class
More informationArgument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.
Local Variable Initialization Unlike instance vars, local vars must be initialized before they can be used. Eg. void mymethod() { int foo = 42; int bar; bar = bar + 1; //compile error bar = 99; bar = bar
More informationOVERRIDING. 7/11/2015 Budditha Hettige 82
OVERRIDING 7/11/2015 (budditha@yahoo.com) 82 What is Overriding Is a language feature Allows a subclass or child class to provide a specific implementation of a method that is already provided by one of
More informationPolymorphism. Zimmer CSCI 330
Polymorphism Polymorphism - is the property of OOP that allows the run-time binding of a function's name to the code that implements the function. (Run-time binding to the starting address of the code.)
More informationAP CS Unit 6: Inheritance Notes
AP CS Unit 6: Inheritance Notes Inheritance is an important feature of object-oriented languages. It allows the designer to create a new class based on another class. The new class inherits everything
More informationHAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.
HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all
More informationRelationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: "has a" CSE143 Sp Student.
CSE 143 Java Object & Class Relationships Inheritance Reading: Ch. 9, 14 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches
More informationCSEN401 Computer Programming Lab. Topics: Object Oriented Features: Abstraction and Polymorphism
CSEN401 Computer Programming Lab Topics: Object Oriented Features: Abstraction and Polymorphism Prof. Dr. Slim Abdennadher 23.2.2015 c S. Abdennadher 1 Object-Oriented Paradigm: Features Easily remembered
More informationMore About Objects. Zheng-Liang Lu Java Programming 255 / 282
More About Objects Inheritance: passing down states and behaviors from the parents to their children. Interfaces: requiring objects for the demanding methods which are exposed to the outside world. Polymorphism
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More informationWhat is Inheritance?
Inheritance 1 Agenda What is and Why Inheritance? How to derive a sub-class? Object class Constructor calling chain super keyword Overriding methods (most important) Hiding methods Hiding fields Type casting
More informationObject-Oriented Concept
Object-Oriented Concept Encapsulation ADT, Object Inheritance Derived object Polymorphism Each object knows what it is Polymorphism noun, the quality or state of being able to assume different forms -
More informationCOSC 121: Computer Programming II. Dr. Bowen Hui University of Bri?sh Columbia Okanagan
COSC 121: Computer Programming II Dr. Bowen Hui University of Bri?sh Columbia Okanagan 1 Quick Review Representa?ve example: Animal[] mypets = new Animal[4]; mypets[0] = new Dog(); mypets[1] = new Cat();
More informationVIRTUAL FUNCTIONS Chapter 10
1 VIRTUAL FUNCTIONS Chapter 10 OBJECTIVES Polymorphism in C++ Pointers to derived classes Important point on inheritance Introduction to virtual functions Virtual destructors More about virtual functions
More informationRelationships Between Real Things CSE 143. Common Relationship Patterns. Employee. Supervisor
CSE 143 Object & Class Relationships Inheritance Reading: Ch. 9, 14 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches dog Dog
More informationSuperclasses / subclasses Inheritance in Java Overriding methods Abstract classes and methods Final classes and methods
Lecture 12 Summary Inheritance Superclasses / subclasses Inheritance in Java Overriding methods Abstract classes and methods Final classes and methods Multiplicity 1 By the end of this lecture, you will
More informationObject-Oriented Concepts and Design Principles
Object-Oriented Concepts and Design Principles Signature Specifying an object operation or method involves declaring its name, the objects it takes as parameters and its return value. Known as an operation
More informationExercise: Singleton 1
Exercise: Singleton 1 In some situations, you may create the only instance of the class. 1 class mysingleton { 2 3 // Will be ready as soon as the class is loaded. 4 private static mysingleton Instance
More informationContents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance
Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass
More informationRelationships Between Real Things CSC 143. Common Relationship Patterns. Composition: "has a" CSC Employee. Supervisor
CSC 143 Object & Class Relationships Inheritance Reading: Ch. 10, 11 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches dog
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 05: Inheritance and Interfaces MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Inheritance and Interfaces 2 Introduction Inheritance and Class Hierarchy Polymorphism Abstract Classes
More informationObject Model. Object Oriented Programming Spring 2015
Object Model Object Oriented Programming 236703 Spring 2015 Class Representation In Memory A class is an abstract entity, so why should it be represented in the runtime environment? Answer #1: Dynamic
More informationInheritance (Outsource: )
(Outsource: 9-12 9-14) is a way to form new classes using classes that have already been defined. The new classes, known as derived classes, inherit attributes and behavior of the pre-existing classes,
More informationInheritance in Ruby. You are familiar with the idea of inheritance and how to use this in programming.
Inheritance in Ruby You are familiar with the idea of inheritance and how to use this in programming. In this introduction, I'll describe inheritance in Ruby from scratch. Much of this material should
More informationOOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.
OOPs Concepts 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. Type Casting Let us discuss them in detail: 1. Data Hiding: Every
More informationOBJECT ORIENTED PROGRAMMING USING C++
OBJECT ORIENTED PROGRAMMING USING C++ 1 Overloading, Overriding POLYMORPHISM poly morphos many forms Overloading single method name having several alternative implementations. Overriding child class provides
More informationInheritance. Transitivity
Inheritance Classes can be organized in a hierarchical structure based on the concept of inheritance Inheritance The property that instances of a sub-class can access both data and behavior associated
More informationWhat are the characteristics of Object Oriented programming language?
What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is
More informationDerived and abstract data types. TDT4205 Lecture 15
1 Derived and abstract data types TDT4205 Lecture 15 2 Where we were We ve looked at static semantics for primitive types and how it relates to type checking We ve hinted at derived types using a multidimensional
More informationECE 122. Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Lecture 22 Polymorphism using Interfaces Overview Problem: Can we delay decisions regarding which method to use until run time? Polymorphism Different methods
More informationCS 403/503 Exam 4 Spring 2015 Solution
CS 403/503 Exam 4 Spring 2015 Solution Each problem initially scored out of 10 points possible. CS 403 Best 5 answers doubled. (5*20 + 2*10 = 120 possible) CS 503 Best 4 answers doubled. (4*20 + 3*10 =
More informationExample: Count of Points
Example: Count of Points 1 public class Point { 2... 3 private static int numofpoints = 0; 4 5 public Point() { 6 numofpoints++; 7 } 8 9 public Point(int x, int y) { 10 this(); // calling Line 5 11 this.x
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 05: Inheritance and Interfaces MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Inheritance and Interfaces 2 Introduction Inheritance and Class Hierarchy Polymorphism Abstract
More informationIntroduction to Scientific Programming with C++
Introduction to Scientific Programming with C++ Session 5: Advanced object oriented programming Martin Uhrin edited by Andrew Maxwell and Ahmed Al Refaie UCL November 6, 2016 1 / 24 Table of Contents 1
More informationInheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object.
Inheritance in Java 1. Inheritance 2. Types of Inheritance 3. Why multiple inheritance is not possible in java in case of class? Inheritance in java is a mechanism in which one object acquires all the
More informationPolymorphism and Inheritance
Walter Savitch Frank M. Carrano Polymorphism and Inheritance Chapter 8 Objectives Describe polymorphism and inheritance in general Define interfaces to specify methods Describe dynamic binding Define and
More informationChapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc.
Chapter 13 Object Oriented Programming Contents 13.1 Prelude: Abstract Data Types 13.2 The Object Model 13.4 Java 13.1 Prelude: Abstract Data Types Imperative programming paradigm Algorithms + Data Structures
More informationLecture 7: Type Systems and Symbol Tables. CS 540 George Mason University
Lecture 7: Type Systems and Symbol Tables CS 540 George Mason University Static Analysis Compilers examine code to find semantic problems. Easy: undeclared variables, tag matching Difficult: preventing
More informationObject interconnections
Object interconnections 2 Roadmap In this chapter we move up a level of abstraction, and consider collections of objects working together Our focus will be on how objects are connected to each other, and
More informationtype conversion polymorphism (intro only) Class class
COMP 250 Lecture 33 type conversion polymorphism (intro only) Class class Nov. 24, 2017 1 Primitive Type Conversion double float long int short char byte boolean non-integers integers In COMP 273, you
More informationInheritance, polymorphism, interfaces
Inheritance, polymorphism, interfaces "is-a" relationship Similar things (sharing same set of attributes / operations): a group / concept Similar groups (sharing a subset of attributes / operations): a
More informationThe Sun s Java Certification and its Possible Role in the Joint Teaching Material
The Sun s Java Certification and its Possible Role in the Joint Teaching Material Nataša Ibrajter Faculty of Science Department of Mathematics and Informatics Novi Sad 1 Contents Kinds of Sun Certified
More informationLecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction
Lecture 13: Object orientation Object oriented programming Introduction, types of OO languages Key concepts: Encapsulation, Inheritance, Dynamic binding & polymorphism Other design issues Smalltalk OO
More informationCOMP200 INTERFACES. OOP using Java, from slides by Shayan Javed
1 1 COMP200 INTERFACES OOP using Java, from slides by Shayan Javed Interfaces 2 ANIMAL picture food sleep() roam() makenoise() eat() 3 ANIMAL picture food sleep() roam() makenoise() eat() 4 roam() FELINE
More informationM301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism
Block 1: Introduction to Java Unit 4: Inheritance, Composition and Polymorphism Aims of the unit: Study and use the Java mechanisms that support reuse, in particular, inheritance and composition; Analyze
More informationInheritance and Polymorphism
Division of Mathematics and Computer Science Maryville College Outline Inheritance 1 Inheritance 2 3 Outline Inheritance 1 Inheritance 2 3 The "is-a" Relationship The "is-a" Relationship Object classification
More informationHAS-A Relationship. If A uses B, then it is an aggregation, stating that B exists independently from A.
HAS-A Relationship Association is a weak relationship where all objects have their own lifetime and there is no ownership. For example, teacher student; doctor patient. If A uses B, then it is an aggregation,
More informationInheritance and Polymorphism
Division of Mathematics and Computer Science Maryville College Outline Inheritance 1 Inheritance 2 3 Outline Inheritance 1 Inheritance 2 3 The "is-a" Relationship Object classification is typically hierarchical.
More informationObject Orientated Programming Details COMP360
Object Orientated Programming Details COMP360 The ancestor of every action is a thought. Ralph Waldo Emerson Three Pillars of OO Programming Inheritance Encapsulation Polymorphism Inheritance Inheritance
More informationCSE 307: Principles of Programming Languages
CSE 307: Principles of Programming Languages Classes and Inheritance R. Sekar 1 / 52 Topics 1. OOP Introduction 2. Type & Subtype 3. Inheritance 4. Overloading and Overriding 2 / 52 Section 1 OOP Introduction
More informationChapter 5 Object-Oriented Programming
Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares
More informationConcepts of Programming Languages
Concepts of Programming Languages Lecture 10 - Object-Oriented Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages
More informationObject Oriented Programming עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון
Object Oriented Programming עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 General Information Instructor: Azzam Maraee Office: building 37, room 205 Email: mari@cs.bgu.ac.il Course WEB site: http://www.cs.bgu.ac.il/~oosd142/
More informationNeed to store a list of shapes, each of which could be a circle, rectangle, or triangle
CS112-2012S-23 Abstract Classes and Interfaces 1 23-0: Drawing Example Creating a drawing program Allow user to draw triangles, circles, rectanlges, move them around, etc. Need to store a list of shapes,
More informationOutline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring
Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,
More informationDesign Patterns גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון
Design Patterns גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Problem: Reusability in OO Designing OO software is hard, and designing reusable OO software is even harder: Software should be specific
More informationC++ Programming: Introduction to C++ and OOP (Object Oriented Programming)
C++ Programming: Introduction to C++ and OOP (Object Oriented Programming) 2018 년도 2 학기 Instructor: Young-guk Ha Dept. of Computer Science & Engineering Contents Brief introduction to C++ OOP vs. Procedural
More informationChapter 1: Object-Oriented Programming Using C++
Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms
More informationObject-Oriented ProgrammingInheritance & Polymorphism
Inheritance Polymorphism Overriding and Overloading Object-Oriented Programming Inheritance & Polymorphism Inf1 :: 2008/09 Inheritance Polymorphism Overriding and Overloading 1 Inheritance Flat Hierarchy
More information1 Shyam sir JAVA Notes
1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write
More informationConcepts of Object Oriented Programming
Concepts of Object Oriented Programming Dr. Axel Kohlmeyer Senior Scientific Computing Expert Information and Telecommunication Section The Abdus Salam International Centre for Theoretical Physics http://sites.google.com/site/akohlmey/
More informationCS 61B Discussion 4: Inheritance Fall 2018
CS 61B Discussion 4: Inheritance Fall 2018 1 Creating Cats Given the Animal class, fill in the definition of the Cat class so that it makes a "Meow!" noise when greet() is called. Assume this noise is
More informationInheritance, Polymorphism, and Interfaces
Inheritance, Polymorphism, and Interfaces Chapter 8 Inheritance Basics (ch.8 idea) Inheritance allows programmer to define a general superclass with certain properties (methods, fields/member variables)
More informationInheritance and object compatibility
Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not the other way around Examples: reference/pointer can
More informationCS 162, Lecture 25: Exam II Review. 30 May 2018
CS 162, Lecture 25: Exam II Review 30 May 2018 True or False Pointers to a base class may be assigned the address of a derived class object. In C++ polymorphism is very difficult to achieve unless you
More informationOverview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008
Overview Lecture 7: Inheritance and GUIs Written by: Daniel Dalevi Inheritance Subclasses and superclasses Java keywords Interfaces and inheritance The JComponent class Casting The cosmic superclass Object
More informationSome instance messages and methods
Some instance messages and methods x ^x y ^y movedx: dx Dy: dy x
More informationInheritance (an intuitive description)
Inheritance (an intuitive description) Recall the Orange class properties found in Orange are also shared with other Fruits (e.g. Apple, Banana, Pineapple) We associate behavior as well as state with with
More informationInstance Members and Static Members
Instance Members and Static Members You may notice that all the members are declared w/o static. These members belong to some specific object. They are called instance members. This implies that these
More informationCHAPTER 5 GENERAL OOP CONCEPTS
CHAPTER 5 GENERAL OOP CONCEPTS EVOLUTION OF SOFTWARE A PROGRAMMING LANGUAGE SHOULD SERVE 2 RELATED PURPOSES : 1. It should provide a vehicle for programmer to specify actions to be executed. 2. It should
More informationC++ & Object Oriented Programming Concepts The procedural programming is the standard approach used in many traditional computer languages such as BASIC, C, FORTRAN and PASCAL. The procedural programming
More informationProgramming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017
Programming Language Concepts Object-Oriented Programming Janyl Jumadinova 28 February, 2017 Three Properties of Object-Oriented Languages: Encapsulation Inheritance Dynamic method binding (polymorphism)
More informationObject Model. Object Oriented Programming Winter
Object Model Object Oriented Programming 236703 Winter 2014-5 Class Representation In Memory A class is an abstract entity, so why should it be represented in the runtime environment? Answer #1: Dynamic
More informationData Abstraction. Hwansoo Han
Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed
More informationOOP in Java Review. CS356 Object-Oriented Design and Programming October 1, 2014
OOP in Java Review CS356 Object-Oriented Design and Programming http://cs356.yusun.io October 1, 2014 Yu Sun, Ph.D. http://yusun.io yusun@csupomona.edu Announcement Submit your GitHub username as soon
More informationChapter 15. Polymorphism and Virtual Functions. Copyright 2010 Pearson Addison-Wesley. All rights reserved
Chapter 15 Polymorphism and Virtual Functions Copyright 2010 Pearson Addison-Wesley. All rights reserved Learning Objectives Virtual Function Basics Late binding Implementing virtual functions When to
More informationAtelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.
marwan.burelle@lse.epita.fr http://wiki-prog.kh405.net Plan 1 2 Plan 3 4 Plan 1 2 3 4 A Bit of History JAVA was created in 1991 by James Gosling of SUN. The first public implementation (v1.0) in 1995.
More informationQUESTIONS FOR AVERAGE BLOOMERS
MANTHLY TEST JULY 2017 QUESTIONS FOR AVERAGE BLOOMERS 1. How many types of polymorphism? Ans- 1.Static Polymorphism (compile time polymorphism/ Method overloading) 2.Dynamic Polymorphism (run time polymorphism/
More information